<template>
	<view class="page-scroller">
		<view style="width: 100%;
    height: 30px;
    padding-top: 10px;
    margin-left: 30%;">
			<span>合计分润 : </span><span>{{amount}} 元</span>
		</view>
		
		
		
			
		<cl-select v-model="params.searchDate"
		                 :options="dateList"  @change="onSearchDate"
		                 label-key="title"
		                 value-key="value"></cl-select>
		
		
		<!-- <cl-select v-model="params.fenrunchanpinID2x84"
		                 :options="productIdList"  @change="onSearch"
		                 label-key="title"
		                 value-key="value"></cl-select> -->
		<cl-scroller class="scroller" ref="scroller" :refresher-enabled="false" @up="onUp" @down="onDown">

			<cl-list-item ref="supItem" type="success" justify="start" swipe="none" class="card-list"
				v-for="(item,index) in dataList" :key="index"
				@tap="item.infoStatusId == '1'? null:navTo('/pages/customer/ViewCustomer/ViewCustomer?id='+item.id)">
				<view class="content">
					<view class="info">
						<!-- <cl-text :ellipsis="15" :value="'分润人： '+(item.name60d8)"></cl-text> -->
						<cl-text :ellipsis="15" :value="'酒店： '+(item.storeName)"></cl-text>
						<cl-text :ellipsis="15"
							:value="'会员类型： '+(item.productName)">
						</cl-text>
						<!-- <cl-text :ellipsis="15"
							:value="'订单ID： '+(item.dingdanIDld4i)"></cl-text> -->
						<cl-text :ellipsis="15"
							:value="'订单金额： '+(item.dingdanjine09y3) +'元'"></cl-text>
						<cl-text :ellipsis="15"
							:value="'分润金额： '+(item.fenrunjinee68c) +'元'"></cl-text>
						<cl-text :ellipsis="15" :value="'下单时间： '+item.dingdanriqi7n1v"></cl-text>
					</view>
				</view>
<!-- 				<view class="append" slot="menu">
					<button class="primary-btn" @click="editRecord(index,item.id)">编辑</button>
				</view> -->

			</cl-list-item>
			<view class="nodata" v-if="dataList.length == 0">
				<view class="nodata-box" style="width: 80px;height: 60px;margin: 80px auto;">
					<image style="width: 80px; height: 60px;" src="@/static/noData.png"></image>
					<text style="color: #999999;font-size: 15px;">暂无数据！</text>
				</view>
			</view>
		</cl-scroller>
	</view>
</template>

<script>
	import api from "@/api/api"
	import helper from "@/utils/helper"
	export default {
		data() {
			return {
				loading: false,
				adv: {
					visible: false,
					form: {
						customerName: "",
					}
				},
				productIdList:[
					{
						title:'全部',
						value:'',
					},
					{
						title:'月卡会员',
						value:'1642782083162161154',
					},
					{
						title:'年卡会员',
						value:'1642781673038921730',
					}
				],
				dateList:[
					{
						title:'所有',
						value:'4',
					},
					{
						title:'今天',
						value:'1',
					},
					{
						title:'昨天',
						value:'2',
					},
					{
						title:'本月',
						value:'3',
					}
					
				],
				amount:0,
				params: {
					pageSize: 10,
					pageNo: 1,
					fenrunrendianhua3m88: uni.getStorageSync('userInfo').userLoginId,
					column: 'rowid',
					order: 'desc'
				},
				dataList: [],
			};
		},
		filters: {
			formatSearch(date) {
				if (date) {
					let value = ''
					if (date[1] != '') {
						value = date.join(' 至 ')
					} else {
						value = date[0]
					}
					return value
				} else {
					return
				}

			},
			formatDate(time) {
				let date = "";
				if (time != 'undefined' && time != undefined) {
					date = time.substr(0, 10)
				} else {
					date = "无";
				}

				return date
			}
		},

		created() {

		},
		onShow() {
			let userInfo = uni.getStorageSync('userInfo');
			if(!userInfo){
				uni.navigateTo({
					url: '/pages/public/login'
				});
			}	
			
			this.initData();
		},
		onPullDownRefresh() {
			setTimeout(() => {
				this.refresh()
				this.$refs["scroller"].end();
				uni.stopPullDownRefresh();
			}, 800);
		},
		onReachBottom() { //上拉触底函数
			if (!this.loading) { //此处判断，上锁，防止重复请求
				this.onUp()
			}
		},
		methods: {
			onSearchDate(e) {
				console.log(e);
				if(e == 1){
					let date = this.getDate(0);
					this.params.dingdanriqi7n1v_fld0_value =date + ' 00:00:00';
					this.params.dingdanriqi7n1v_fld1_value =date + ' 23:59:59';
				}else if(e == 2){
					let date = this.getDate(1);
					this.params.dingdanriqi7n1v_fld0_value =date + ' 00:00:00';
					this.params.dingdanriqi7n1v_fld1_value =date + ' 23:59:59';
				}else if(e == 3){ //本月
					let date = this.getNowMonth();
					this.params.chuangjiannianyue4c37 =date;
					delete this.params.dingdanriqi7n1v_fld0_value
					delete this.params.dingdanriqi7n1v_fld1_value
				}else{
					delete this.params.dingdanriqi7n1v_fld0_value
					delete this.params.dingdanriqi7n1v_fld1_value
					delete this.params.chuangjiannianyue4c37
				}
				this.params.pageNo = 1;
				this.queryList()
			},
			//返回当前日期
			
			getDate(dayNum) {
				var date = new Date();
				date.setTime(date.getTime() - dayNum * 24 * 60 * 60 * 1000);
				let year = date.getFullYear(); //获取完整的年份(4位)
				let month = date.getMonth() + 1; //获取当前月份(0-11,0代表1月)
				let day = date.getDate(); //获取当前日(1-31)
				if (month < 10) {
					month = "0" + month;
				}
				if (day < 10) {
					day = "0" + day;
				}
				return year + '-' + month + '-' + day;
			},
			getNowMonth() {
				var date = new Date();
				let year = date.getFullYear(); //获取完整的年份(4位)
				let month = date.getMonth() + 1; //获取当前月份(0-11,0代表1月)
				let day = date.getDate(); //获取当前日(1-31)
				if (month < 10) {
					month = "0" + month;
				}
				return year + '-' + month;
			},
			getNowDate() {
				var date = new Date();
				let year = date.getFullYear(); //获取完整的年份(4位)
				let month = date.getMonth() + 1; //获取当前月份(0-11,0代表1月)
				let day = date.getDate(); //获取当前日(1-31)
				if (month < 10) {
					month = "0" + month;
				}
				if (day < 10) {
					day = "0" + day;
				}
				return year + '-' + month + '-' + day;
			},
			getDaysBetween(dateString1, dateString2) {
				var startDate = Date.parse(dateString1);
				var endDate = Date.parse(dateString2);
				if (startDate > endDate) {
					return 0;
				}
				if (startDate == endDate) {
					return 1;
				}
				var days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000);
				return days;
			},
			resetSearchDate() {
				this.params = {
					paymentTypeId: '0',
					pageSize: 10,
					pageNo: 1,
					ownerUserId: uni.getStorageSync('userInfo').userLoginId,
					column: 'createTime',
					order: ''
				}
				this.queryList()
				this.$refs["scroller"].end();
			},
			onSubmit() {
				for (let key in this.adv.form) {
					this.params[key] = this.adv.form[key];
				}
				this.queryList()
				this.adv.visible = false;
			},
			onChange(e) {
				this.queryList()
			},
			toAdvSearch() {
				this.$refs["filter-bar"].close();
				this.adv.visible = true;
			},
			// 数据初始化
			initData() {
				uni.setNavigationBarColor({
					frontColor: '#ffffff',
					backgroundColor: this.themeColor.color,
					animation: {
						duration: 400,
						timingFunc: 'easeIn'
					}
				})
				this.params.pageNo = 1;
				this.queryList()
			},
			navTo(route) {
				this.$mRouter.push({
					route
				});
			},
			onSearch() {
				this.queryList()
			},
			refresh() {
				this.params.pageNo = 1
				this.params.pageSize = 10
				this.queryList()
				this.$refs["scroller"].end();
			},
			// 获取列表数据
			queryList() {
				let that = this;
				that.loading = true;
				that.$http.post(api.listShopRuleHistory, that.params).then(function(res) {
					that.dataList = res.result.records
					that.amount = res.result.amount;
					that.loading = false
				});
			},
			onUp() {
				let that = this;
				that.loading = true;
				that.params.pageNo = that.params.pageNo + 1
				that.$http.post(api.listShopRuleHistory, that.params).then(function(res) {
					if (res.code == '0') {
						that.amount = res.result.amount;
						if (res.result.records) {
							that.dataList = that.dataList.concat(res.result.records)
							if (res.result.records.length < that.params.pageSize) {
								that.loading = true
							} else {
								that.loading = false
								that.$refs["scroller"].end();
							}
						} else {
							that.loading = true
						}
					} else {
						that.loading = false
						if (that.params.pageNo > 1) {
							that.params.pageNo -= 1
						}
					}
				});
			},
			onDown() {
				setTimeout(() => {
					this.refresh()
					this.$refs["scroller"].end();
				}, 800);
			},
		}
	};
</script>

<style lang="scss" scoped>
	.page-scroller {

		.footer {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			background-color: #fff;
			z-index: 9;
			padding: 10rpx 20rpx;
			box-sizing: border-box;
			border-top: 1rpx solid #eee;
			padding-bottom: calc(env(safe-area-inset-bottom) + 10rpx);
		}

		height: 100%;
		min-height: 400px;
		overflow: hidden;
		box-sizing: border-box;

		.scroller {
			height: calc(100% - 84px);
		}

		/deep/.cl-filter-bar__wrap {
			border-bottom: 1rpx solid #dcdfe6;
		}

		/deep/.cl-list-item {
			background-color: #fff;
			border-bottom: 1rpx solid #dcdfe6;
		}


		.cs-block {
			display: flex;
			align-items: center;

			/deep/.cl-avatar {
				height: 120rpx !important;
				width: 120rpx !important;
				margin-right: 30rpx;
				border-radius: 10rpx;
			}
		}

		.content {
			position: relative;
			color: #777777;
			display: flex;
			align-items: flex-start;
			width: 75%;
			min-height: 66px;
			flex-direction: column;

			.info {
				margin-left: 10px;
			}

			.bottom {
				width: 100%;
				height: 100%;


				.time {
					align-items: flex-end !important;
					width: auto;
					margin-left: auto !important;
				}
			}
		}

		.append {
			display: flex;
			height: 100%;

			.primary-btn,
			.error-btn {
				height: 100% !important;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 0;
				height: 100rpx;
				width: 130rpx;
				font-size: 26rpx;
				color: #fff;
				box-sizing: border-box;
				margin: 0;
				border: 0;

				&::after {
					border: 0;
				}
			}

			.primary-btn {
				background-color: #39b54a;
			}

			.error-btn {
				background-color: $uni-color-error;
			}
		}
	}
</style>
